$(document).ready(function () {
  var Main = {
    created() {
      this.getMenus();
      this.getSigns();
      this.getTpzlList();
      this.getTzggList();
      this.getSxtzList();
      this.getKjdtList();
      this.getGbList();
      this.getGsList();
      this.getKjjsList();
      this.getZcfgList();
      this.getTeaActivityList();
      this.getList();
    },
    filters: {
      formateDate(time) {
        return new Date(time).Format("yyyy-MM-dd");
      },
    },
    data() {
      return {
        //友情链接导航
        linkList:[],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          platformName: null,
          logo: null,
          linkUrl: null,
          platformKey: null,
          saveTime: null,
          statusCd: null,
          type:'',
        },
        typeNameList:[
          {value:'广州市公益科普基地',label:'广州市公益科普基地'},
          {value:'公益课堂',label:'公益课堂'},
          {value:'学校',label:'学校'}
        ],
        openFlag: false, // 是否打开友情资源导航
        nowDate: new Date().getTime(),
        // interfaceUrl: "http://kpg.gzjkw.net/innovateActivity",
        interfaceUrl: "http://120.238.175.104:89/innovateActivity",
        signUpUrl: "http://kpg.gzjkw.net/innovateActivityPage/#/teaActivity/teaSignUp",
        signUpBackUrl: "http://kpg.gzjkw.net/innovateActivityPage",
        ctx: ctx,
        kpgmh: kpgmh,
        teaActivityList: [],
        zcfg_list: [],
        gs_list: [],
        gb_list: [],
        tzgg_list: [],
        kjjs_list: [],
        sxtz_list: [],
        kjdt_list: [],
        activity_list: [],
        tpzl_list: [],
        xiangmu_list: [],
        jiaoshiActivities: [],
        jiGous: [],
        menus: [],
        zcfg: "",
        tzgg: "",
        gs: "",
        gb: "",
        kjjs: "",
        sxtz: "",
        kjdt: "",
        userType: userType,
        kpsbcrac: kpsbcrac,
        kpsbsecurbm: kpsbsecurbm,

        openMenuIndex: -1,
        openMenuIndex2: -1,
        menuList: [
          {
            label: "项目与活动管理",
            value: "M01",
            path: "",
            children: [
              {
                label: "教育科普项目",
                value: "xiangmushenbao",
                path: "https://kpg.gzjkw.net/kpsb/login.zul?service=http://kpg.gzjkw.net/kpsb/security_check",
              },
              {
                label: "竞赛活动",
                value: "kejitiyu",
                path: "",
                children: [
                  {
                    label: "科技体育",
                    value: "kejitiyu",
                    path: "https://kpg.gzjkw.net/innovateActivityPage/#/forward/sportsActivities/activityIndex",
                  },
                  {
                    label: "创新创业大赛",
                    value: "chuangxindasai",
                    path: "https://kpg.gzjkw.net/innovateActivityPage/#/forward/innovationActivities/activityIndex",
                  },
                ],
              },
              {
                label: "实践探究",
                value: "",
                path: "",
                children: [
                  {
                    label: "夏令营",
                    value: "xialingying",
                    path:"http://kpg.gzjkw.net/innovateActivityPage/#/forward/activityIndex"
                    // path: (userType=='SJYJ' || userType=='C')?"http://kpg.gzjkw.net/innovateActivityPage/#/forward/activityIndex":"http://kpg.gzjkw.net/innovateActivity/",
                  },
                ],
              },
            ],
          },
          {
            label: "数据与资料管理",
            value: "M02",
            path: "",
            children: [
              { label: "绿色学校", value: "lvsexuexiao", path: "http://kpg.gzjkw.net/lsxxPage/#/login?redirect=%2F" },
              { label: "垃圾分类", value: "lajifenlei", path: "http://kpg.gzjkw.net/wastePage/#/login?redirect=%2F" },

              {
                label: "证书管理",
                value: "",
                path: "",
                children: [
                  { label: "广州市教育局电子证书系统", value: "", path: "http://kpg.gzjkw.net/zs/" },
                  { label: "科技类证书登记与核对", value: "", path: "https://kpg.gzjkw.net/kjjsdjPage/login" },
                ],
              },
              // { label: "专家库", value: "", path: "http://kpg.gzjkw.net/expertDatabase/login" },
            ],
          },
          {
            label: "科教资源",
            value: "M03",
            path: "http://kpg.gzjkw.net/zxxx",
            children: [],
          },
        ],

        homeTab1: ['活动报名'],
        homeTabIndex1: 0,

        homeTab2: ['科技动态', '图片新闻'],
        homeTabIndex2: 0,

        homeTab3: ['通知公告', '公示', '公布'],
        homeTabIndex3: 0,
      };
    },
    methods: {
      handleClickTab1(index){
        this.homeTabIndex1 = index;
        if(index == 0){
          // 活动报名
          this.getSigns();
        }
      },
      handleClickTab2(index){
        this.homeTabIndex2 = index;
        if(index == 0){
          // 科技动态
          this.getKjdtList();
        }else if(index == 1){
          // 图片新闻
        }
      },
      handleClickTab3(index){
        this.homeTabIndex3 = index;
        if(index == 0){
          // 通知公告
          this.getKjdtList();
        }else if(index == 1){
          // 公示
          this.getGsList();
        }else if(index == 2){
          // 公布
          this.getGbList();
        }
      },
      handleMouseEnter2(index, cIndex) {
        this.openMenuIndex2 = index + "_" + cIndex;
      },
      handleMouseLeave2() {
        this.openMenuIndex2 = -1;
      },
      handleMouseEnter(index) {
        this.openMenuIndex = index;
      },
      handleMouseLeave() {
        this.openMenuIndex = -1;
      },
      handleClickMenu(index) {
        // if (this.openMenuIndex != index) {
        //   this.openMenuIndex = index;
        // } else {
        //   this.openMenuIndex = -1;
        // }
      },
      handleClickMenuChildren(cItem) {
        console.log(cItem);
        if (!cItem.path) {
          alert("菜单的path为空");
          return;
        }

        $('#myModal2').modal({backdrop: 'static', keyboard: false});
        $('#myModal2').modal('show');
        // window.open(cItem.path);
        this.path = cItem.path;
      },
      handleTo(){
        if (!this.path) {
          alert("菜单的path为空");
          return;
        }
        window.open(this.path);
        $('#myModal2').modal('hide');
      },
      // 切换tabs
      handleTabsClick(value) {
        if(this.queryParams.type == value){
          this.queryParams.type = '';
          this.openFlag = !this.openFlag;
        }else{
          this.openFlag = true;
          this.queryParams.type = value;
          this.getList();
        }
      },
      /** 查询友情链接管理列表 */
      getList() {
        if(!this.queryParams.type) return;
        let that = this;
        $.ajax({
          type: "get",
          url: that.interfaceUrl + "/sys/friendLink/list?pageNum=1&pageSize=999&type="+ this.queryParams.type,
          success: function (data) {
            that.linkList = data.rows;
          },
        });
      },

      getSigns() {
        let that = this;
        $.ajax({
          type: "POST",
          url: ctx + "/getSigns.do",
          data: { pageSize: 5 },
          success: function (data) {
            that.xiangmu_list = data.xiangmus;
            that.activity_list = data.activities;
            that.jiaoshiActivities = data.jiaoshiActivities;
            that.jiGous = data.jiGous;
            that.$nextTick(function () {
              let aLi = $(".hdul").children();
              $.each(aLi, function (index, term) {
                term.onmouseover = function () {
                  $(this).children("a").eq(1).children("img").attr("src", "images/first/baomingselect.png");
                  $(this).children("img").attr("src", "images/first/3_0000.png");
                };
                term.onmouseleave = function () {
                  $(this).children("a").eq(1).children("img").attr("src", "images/first/baomin.png");
                  $(this).children("img").attr("src", "images/first/3_0001.png");
                };
              });

              aLi = $(".jshdul").children();
              $.each(aLi, function (index, term) {
                term.onmouseover = function () {
                  $(this).children("a").eq(1).children("img").attr("src", "images/first/baomingselect.png");
                  $(this).children("img").attr("src", "images/first/3_0000.png");
                };
                term.onmouseleave = function () {
                  $(this).children("a").eq(1).children("img").attr("src", "images/first/baomin.png");
                  $(this).children("img").attr("src", "images/first/3_0001.png");
                };
              });

              aLi = $(".xmul").children();
              $.each(aLi, function (index, term) {
                term.onmouseover = function () {
                  $(this).children("a").eq(1).children("img").attr("src", "images/first/xmbaomingselect.png");
                  $(this).children("img").attr("src", "images/first/3_0000.png");
                };
                term.onmouseleave = function () {
                  $(this).children("a").eq(1).children("img").attr("src", "images/first/xmbaomin.png");
                  $(this).children("img").attr("src", "images/first/3_0001.png");
                };
              });

              let aDiv = $("#top_title").children();
              $.each(aDiv, function (index, term) {
                term.onclick = function () {
                  $(this).siblings("div").removeClass("active");
                  $(this).addClass("active");
                  if (index == 1) {
                    $(".xmul").show();
                    $(".hdul").hide();
                    $(".jshdul").hide();
                    $("#gmore").attr("href", that.ctx + "/getMoreXm.do?pageIndex=1");
                  } else if (index == 0) {
                    $("#gmore").attr("href", that.ctx + "/getMore.do?pageIndex=1");
                    $(".hdul").show();
                    $(".xmul").hide();
                    $(".jshdul").hide();
                  } else {
                    $(".jshdul").show();
                    $(".xmul").hide();
                    $(".hdul").hide();
                  }
                };
              });
            });
          },
        });
      },
      getMenus() {
        let that = this;
        $.ajax({
          type: "POST",
          url: ctx + "/getMenus.do",
          data: {},
          success: function (data) {
            that.menus = data.menus;
            that.$nextTick(function () {
              let liLength = $(".common_menu").length;
              let bfb = (100 / liLength).toFixed(2) + "%";
              $(".common_menu").css("width", bfb);
            });
          },
        });
      },
      getTeaActivityList() {
        let that = this;
        $.ajax({
          type: "get",
          url: that.interfaceUrl + "/tea/activity/list?pageNum=1&pageSize=10&isPublic=1",
          success: function (data) {
            that.teaActivityList = data.rows;
            console.log(that.teaActivityList, "teaActivityList");
          },
        });
      },
      getZcfgList() {
        let that = this;
        $.ajax({
          type: "POST",
          url: ctx + "/getNewsData.do",
          data: { menuId: 46, pageSize: 5 },
          success: function (data) {
            that.zcfg_list = data.news_list;
            that.zcfg = data.menu;
          },
        });
      },
      getTpzlList() {
        let that = this;
        $.ajax({
          type: "POST",
          url: ctx + "/getNewsData.do",
          data: { menuId: 36, pageSize: 5 },
          success: function (data) {
            that.tpzl_list = data.news_list;
            that.$nextTick(function () {
              var obj = $("#slideBox");
              var effect = "effect-z1";
              var btns = obj.find(".hd li");
              var con = obj.find(".bd ul");
              var size = con.find("li").size();
              var curIndex = 0;
              var w = obj.width();
              var h = obj.height();
              var sliceNum = 8;
              var running = true;

              obj.find(".bd li").each(function (n) {
                $(this).css({ position: "absolute", top: "0", left: "0", "z-index": size - n });
              });

              //鼠标事件
              btns.click(function () {
                if (!running) {
                  return false;
                }
                curIndex = btns.index($(this));
                $(this).addClass("on").siblings().removeClass("on");
                con.find(".slideClone").remove();
                doEffect(curIndex);
              });

              setInterval(function () {
                if (!running) {
                  return false;
                }
                //curIndex = btns.index($(this));
                $(btns[curIndex]).addClass("on").siblings().removeClass("on");
                con.find(".slideClone").remove();
                doEffect(curIndex);
                curIndex++;
                if (curIndex == 5) {
                  curIndex = 0;
                }
              }, 4000);

              //效果函数
              var doEffect = function (curNum) {
                running = false;
                $(".intro").parent().children(".intro").hide();
                $(".intro").eq(curNum).show();
                var sliceW = Math.round(w / sliceNum) + 1;
                var sliceH = Math.round(h / sliceNum) + 1;
                for (var i = 0; i < sliceNum; i++) {
                  var curClone = con
                    .find("li")
                    .eq(curNum)
                    .clone()
                    .appendTo(con)
                    .addClass("slideClone")
                    .css({
                      width: 0,
                      height: sliceH,
                      top: sliceH * i,
                      overflow: "hidden",
                      opacity: 0,
                      "z-index": size + 1,
                    });
                  curClone.find("img").css({ position: "absolute", left: "0", top: -sliceH * i });
                }
                con.find(".slideClone").each(function (n) {
                  var ss = $(this);
                  setTimeout(function () {
                    ss.animate({ width: w, height: sliceH, opacity: "1" }, 400);
                  }, 70 * n);
                });

                //重置z-index
                setTimeout(function () {
                  for (var i = 0; i < size; i++) {
                    if (i == curNum) {
                      con.find("li").eq(i).css({ "z-index": size });
                    } else {
                      con.find("li").eq(i).css({ "z-index": 1 });
                    }
                  }
                  running = true;
                }, 70 * sliceNum + 400);
              }; //Effect1 E
            });
          },
        });
      },
      getSxtzList() {
        let that = this;
        $.ajax({
          type: "POST",
          url: ctx + "/getNewsData.do",
          data: { menuId: 71, pageSize: 5 },
          success: function (data) {
            that.sxtz_list = data.news_list;
            that.sxtz = data.menu;
          },
        });
      },
      getKjdtList() {
        let that = this;
        $.ajax({
          type: "POST",
          url: ctx + "/getNewsData.do",
          data: { menuId: 65, pageSize: 5 },
          success: function (data) {
            that.kjdt_list = data.news_list;
            that.kjdt = data.menu;
          },
        });
      },
      getGsList() {
        let that = this;
        $.ajax({
          type: "POST",
          url: ctx + "/getNewsData.do",
          data: { menuId: 69, pageSize: 5 },
          success: function (data) {
            that.gs_list = data.news_list;
            that.gs = data.menu;
          },
        });
      },
      getGbList() {
        let that = this;
        $.ajax({
          type: "POST",
          url: ctx + "/getNewsData.do",
          data: { menuId: 64, pageSize: 5 },
          success: function (data) {
            that.gb_list = data.news_list;
            that.gb = data.menu;
          },
        });
      },
      getKjjsList() {
        let that = this;
        $.ajax({
          type: "POST",
          url: ctx + "/getNewsData.do",
          data: { menuId: 46, pageSize: 5 },
          success: function (data) {
            that.kjjs_list = data.news_list;
            that.kjjs = data.menu;
          },
        });
      },
      getTzggList() {
        let that = this;
        $.ajax({
          type: "POST",
          url: ctx + "/getNewsData.do",
          data: { menuId: 35, pageSize: 10 },
          success: function (data) {
            that.tzgg_list = data.news_list;
            that.tzgg = data.menu;
            that.$nextTick(function () {
              $("#second_left").myScroll({
                speed: 60, //数值越大，速度越慢
                rowHeight: 40, //li的高度
              });
            });
          },
        });
      },
    },
    mounted() {},
  };
  var Component = Vue.extend(Main);
  new Component().$mount("#container");
});
